# 输出器
class HtmlOutput(object):

    def __init__(self):
        self.datas = []

    def collect_data(self, new_data):
        if new_data is None:
            return
        self.datas.append(new_data)

    def output_html(self):
        file = open('output.html', 'w')
        file.write('<html>')
        file.write('<body>')
        file.write('<table>')

        for data in self.datas:
            file.write('<tr>')
            file.write('<td>%s</td>' % data['url'])
            file.write('<td>%s</td>' % data['title'].encode('utf-8'))
            file.write('<td>%s</td>' % data['summary'].encode('utf-8'))
            file.write('</tr>')

        file.write('</table>')
        file.write('</body>')
        file.write('</html>')
        file.close()
